using Godot;
using System;

public partial class Explosion : Node2D
{
    [Signal]
    public delegate void ExplosionEndEventHandler();

    AnimationPlayer animationPlayer;
    AudioStreamPlayer audioStreamPlayer;
    public override void _Ready()
    {
        animationPlayer = GetNode<AnimationPlayer>("AnimationPlayer");
        animationPlayer.AnimationFinished += OnAnimationPlayerAnimationFinished;
        audioStreamPlayer = GetNode<AudioStreamPlayer>("AudioStreamPlayer");
    }
    private void OnAnimationPlayerAnimationFinished(StringName animName)
    {
        EmitSignal(SignalName.ExplosionEnd);
        GameManager.Instance.AllowInput();
        Hide();
    }

    public void Play()
    {
        Show();
        GameManager.Instance.LockInput();
        animationPlayer.Play("explosion");
        audioStreamPlayer.Play();
    }
    public void Explode(Vector2 position)
    {
        Position = position;
        Play();
    }
}
